package com.fph.controller;

import cn.hutool.core.lang.Dict;
import com.fph.demo.entity.ApplicationDevYml;
import com.fph.demo.entity.ApplicationYml;
import com.fph.demo.entity.UserEntity;
import com.fph.utils.ValueUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName DemoController
 * @Description TODO
 * @Author fph
 * @Date 2024-07-08 9:52
 **/
@RestController
public class DemoController {

    @Autowired
    private ApplicationYml applicationYml;

    @Autowired
    private ApplicationDevYml applicationDevYml;

    @Autowired
    private Environment environment;

    private UserEntity userEntity;

    @Autowired
    public DemoController(UserEntity user){
        this.userEntity = user;
    }

    @GetMapping("/applicaionyml")
    public Dict index() {
        return Dict.create().set("name", applicationYml.getName())
                .set("developerProperty", applicationYml.getVersion())
                .set("ValueUtilName", ValueUtil.name);
    }

    @GetMapping("/user")
    public Dict userIndex() {
        return Dict.create().set("name", userEntity.getUserName())
                .set("age", userEntity.getAge());
    }

    @GetMapping("/applicaiondevyml")
    public Dict applicaiondevymlIndex() {
        return Dict.create().set("name", applicationDevYml.getName())
                .set("age", applicationDevYml.getAge())
                .set("map", applicationDevYml.getMap());
    }

    @GetMapping("/environment")
    public Dict environmentIndex() {
        return Dict.create().set("lesson", environment.getProperty("lesson"))
                .set("name", environment.getProperty("enterprise.name"))
                .set("subject", environment.getProperty("enterprise.subject[1]"));
    }

}

